﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.Linq;

namespace Radar {
    /// <summary>
    /// Summary description for Radar
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Radar : System.Web.Services.WebService {

        private string connString = @"Data Source=localhost;Initial Catalog=Radar;Integrated Security=true";

        [WebMethod]
        public List<Capture> GetCaptures(DateTime startDate) {
            DataContext dc = new DataContext(connString);
            Table<Capture> tc = dc.GetTable<Capture>();
            var caps = dc.GetTable<Capture>().Where(c => c.date >= startDate);
            return new List<Capture>(caps.AsEnumerable());
        }

        [WebMethod]
        public List<Image> GetImages(int[] captureId) {
            DataContext dc = new DataContext(connString);
            Table<Image> tc = dc.GetTable<Image>();
            var imgs = from c in dc.GetTable<Image>()
                       where captureId.Contains(c.captureId)
                       select c;
            return new List<Image>(imgs.AsEnumerable());
        }
    }
}
